-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add configurable sort modes to file explorer/project panel #40160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @lparry on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
5cc0a83 to
0f247cf
Compare
## Summary Adds three sorting modes for the project panel to give users more control over how files and directories are displayed: - **`directories_first`** (default): Current behaviour - directories grouped before files - **`interleaved`**: Files and directories sorted together alphabetically - **`macos_like`**: Like interleaved, but with case-insensitive sorting (Finder-style) ## Motivation Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style interleaved sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together. ## Changes ### Core Implementation - Added `ProjectPanelSortMode` enum to settings with three variants - Implemented `compare_rel_paths_interleaved()` for mixed file/directory sorting - Implemented `compare_rel_paths_macos_like()` for case-insensitive interleaved sorting - Refactored sorting functions to accept a mode parameter while maintaining backward compatibility - Added `sort_mode` field to `ProjectPanelSettings` with `directories_first` as default ### User Experience - Settings UI integration with dropdown selector in Panels section - Real-time panel updates when sort mode changes - Documentation added to visual-customization.md - All three modes use natural sorting for numbers (e.g., "file2" < "file10") ### Testing & Performance - Comprehensive test coverage including edge cases (basename collisions, nested paths, stability) - Benchmark suite to measure performance across all three modes (interleaved is fastest, followed by macos-like, followed by the current implementation) - Fixed hard-coded path in benchmark to use `CARGO_MANIFEST_DIR` ## Technical Details **Sorting Implementations:** 1. **`directories_first`**: Uses existing `compare_rel_paths()` - directories have inherent priority, then natural sort within each group 2. **`interleaved`**: New `compare_rel_paths_interleaved()` - removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries like `foo/` vs `foo.rs` 3. **`macos_like`**: New `compare_rel_paths_macos_like()` - case-insensitive variant of interleaved using `natural_sort_case_insensitive()` helper **Key Design Decisions:** - Maintained backward compatibility with legacy `sort_worktree_entries()` functions - Used mode-aware wrappers (`sort_worktree_entries_with_mode()`) for new code - Settings observer triggers `update_visible_entries()` when sort mode changes - All sorting happens in-place for performance
0f247cf to
d43b0be
Compare
|
I believe I have resolved the conflict & style linting problems now |
|
@lparry I think there are still a bunch of errors when I try to compile it with |
in initializer of `workspace::ProjectPanelSettingsContent`
This is what vscode calls it and chews up less chars.
|
@smitbarmase That's embarrassing, sorry about that! I've sorted out those errors & the warning, renamed Running a copy of the dev zed bundle for 148da0c built via |
|
I've found a bug in the behaviour where the children of an expanded directory are not anchored correctly to the expected parent directory. I'll see if I can work out where I've gone wrong |
Noticed a bug after using this for a while in that the children of an expanded directory could get separated from the parent directory node by other similiarly named files.
|
@smitbarmase I've sorted out that bug now and added some more exhaustive tests that will hopefully cover more/most of the edge cases likely to come up. Would love your opinion on if the default sort should be based on platform (so macos users automatically get the macos-like sort), or if it should remain as it is with the option of changing it to match the current OS? 🙏 |
|
Sorry to keep iterating on this after opening, but after screenshotting the various states I' realised that the directories first sort is supposed to be case insensitive, but another bug had tricked me into believing otherwise. Realising that I think I can drop the case-sensitive mixed sort, and the near duplicate |
Closes #4533 (partly at least)
Release Notes:
project_panel.sort_modeoption to control explorer file sort (Directories first, mixed, macOS-like)Summary
Adds three sorting modes for the project panel to give users more control over how files and directories are displayed:
directories_first(default): Current behaviour - directories grouped before filesmixed: Files and directories sorted together alphabeticallymacos_like: Like mixed, but with case-insensitive sorting (Finder-style)Motivation
Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style mixed sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together.
Changes
Core Implementation
ProjectPanelSortModeenum to settings with three variantscompare_rel_paths_mixed()for mixed file/directory sortingcompare_rel_paths_macos_like()for case-insensitive mixed sortingsort_modefield toProjectPanelSettingswithdirectories_firstas defaultUser Experience
Screenshots
New sort options in settings:

Testing & Performance
CARGO_MANIFEST_DIRTechnical Details
Sorting Implementations:
directories_first: Uses existingcompare_rel_paths()- directories have inherent priority, then natural sort within each groupmixed: Newcompare_rel_paths_mixed()- removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries likefoo/vsfoo.rsmacos_like: Newcompare_rel_paths_macos_like()- case-insensitive variant of mixed usingnatural_sort_case_insensitive()helperKey Design Decisions:
sort_worktree_entries()functionssort_worktree_entries_with_mode()) for new codeupdate_visible_entries()when sort mode changesAgent usage
Co-pilot/claude-code + claude sonnet 4.5 helped out a lot. I'm not from a rust background, but really wanted this solved